function [out,stats,time_matrix,Log] = Regression_IAT2_1 (DATA_1,listtentwe,electrolist,main_log)
    
         answer = inputdlg({'Start var A (press 0 for log)','End var A (press 0 for log)', 'Samplig rate','Variable one name','Mean or Peak (press 0 for log, 1 - Mean, 2 - peak_max - and also create time matrix            )'});
     
     
         
        if (str2num(cell2mat(answer(3,1))) + 100) == 100;
            sampling_rate = main_log{10,1};
        else
            sampling_rate= str2num(cell2mat(answer(3,1)));
        end           
     
        if (str2num(cell2mat(answer(1,1))) + 100) == 100;
            start_var_A= main_log{1,1};
        else
            start_var_A= str2num(cell2mat(answer(1,1))) + 100;
            start_var_A = round(start_var_A*sampling_rate/1000);
        end
          
        if (str2num(cell2mat(answer(2,1))) + 100) == 100;
            seg_end_var_A= main_log{2,1};
        else
            seg_end_var_A= str2num(cell2mat(answer(2,1))) + 100;
            seg_end_var_A = round(seg_end_var_A*sampling_rate/1000);
        end

        if (str2num(cell2mat(answer(5,1))) + 100) == 100;
           Mean_peak = main_log{16,1};
        else
            Mean_peak= str2num(cell2mat(answer(5,1)));
        end           
         

        if (isempty(str2num(cell2mat(answer(4,1)))))== 0
             Variable_1_name= main_log{15,1};
        else
             Variable_1_name= answer(4,1);
        end      

                
  
        choice = menu('factor A 10 20 map','manual','take from log','take from log and dispaly');        
        if choice == 1            
           Var_A_electrodes = mapchoose(listtentwe,electrolist);
        elseif choice == 2         
           Var_A_electrodes = main_log{7,1};
        elseif choice == 3         
           mapshow(listtentwe,electrolist,main_log{7,1});
           Var_A_electrodes = main_log{7,1};   
        end
        

         
         %%% logging new and old data
                Log{1,1} =  start_var_A;
                Log{2,1} =  seg_end_var_A;
                Log{7,1} =  Var_A_electrodes;
                Log{10,1} =  sampling_rate;
                Log{15,1} =  Variable_1_name;
                Log{16,1} = Mean_peak;

         
%                [Var_A_bootstrap,Var_B_bootstrap] = permeutating_erp_half_and_half(DATA_1,Var_A_electrodes,start_var_A,seg_end_var_A,Var_B_electrodes,start_var_B,seg_end_var_B,5000);
%                disp(Var_A_bootstrap);
%                disp(Var_B_bootstrap);
                
        %this for loop avreages over subjects.
        for i = 1 : length(DATA_1)
            
            
            %this for runs on the selected electrodes and avreages the data between time points (which I use usully for emotion and words).
            
            
            if Mean_peak == 1
                
                         for ii = 1 : length( Var_A_electrodes)

                             temp_vector_for_condition_A1 (i,ii) = mean (DATA_1{i,1}(Var_A_electrodes(1,ii),  start_var_A :seg_end_var_A));
                             temp_vector_for_condition_A2 (i,ii) = mean (DATA_1{i,2}(Var_A_electrodes(1,ii),  start_var_A :seg_end_var_A));
                             temp_vector_for_condition_B1 (i,ii) = mean (DATA_1{i,3}(Var_A_electrodes(1,ii),  start_var_A :seg_end_var_A));
                             temp_vector_for_condition_B2 (i,ii) = mean (DATA_1{i,4}(Var_A_electrodes(1,ii),  start_var_A :seg_end_var_A));

                         end

            elseif Mean_peak == 2
                
                        for ii = 1 : length( Var_A_electrodes)

                             [temp_vector_for_condition_A1(i,ii),temp_time_vector_for_condition_A1(i,ii)] = Mymax (DATA_1{i,1}(Var_A_electrodes(1,ii),  start_var_A :seg_end_var_A),sampling_rate,start_var_A);
                             [temp_vector_for_condition_A2(i,ii),temp_time_vector_for_condition_A2(i,ii)] = Mymax (DATA_1{i,2}(Var_A_electrodes(1,ii),  start_var_A :seg_end_var_A),sampling_rate,start_var_A);
                             [temp_vector_for_condition_B1(i,ii),temp_time_vector_for_condition_B1(i,ii)] = Mymax (DATA_1{i,3}(Var_A_electrodes(1,ii),  start_var_A :seg_end_var_A),sampling_rate,start_var_A);
                             [temp_vector_for_condition_B2(i,ii),temp_time_vector_for_condition_B2(i,ii)] = Mymax (DATA_1{i,4}(Var_A_electrodes(1,ii),  start_var_A :seg_end_var_A),sampling_rate,start_var_A);

                        end             
            elseif Mean_peak == 3
                
                        for ii = 1 : length( Var_A_electrodes)

%                              [temp_vector_for_condition_A1(i,ii),temp_time_vector_for_condition_A1(i,ii)] = Mymin (DATA_1{i,1}(Var_A_electrodes(1,ii),  start_var_A :seg_end_var_A));
%                              [temp_vector_for_condition_A2(i,ii),temp_time_vector_for_condition_A2(i,ii)] = Mymin (DATA_1{i,2}(Var_A_electrodes(1,ii),  start_var_A :seg_end_var_A));
%                              [temp_vector_for_condition_B1(i,ii),temp_time_vector_for_condition_B1(i,ii)] = Mymin (DATA_1{i,3}(Var_A_electrodes(1,ii),  start_var_A :seg_end_var_A));
%                              [temp_vector_for_condition_B2(i,ii),temp_time_vector_for_condition_B2(i,ii)] = MYmin (DATA_1{i,4}(Var_A_electrodes(1,ii),  start_var_A :seg_end_var_A));
                            
                             [temp_vector_for_condition_A1(i,ii),temp_time_vector_for_condition_A1(i,ii)] = Mymin (DATA_1{i,1}(Var_A_electrodes(1,ii),  start_var_A :seg_end_var_A),sampling_rate,start_var_A);
                             [temp_vector_for_condition_A2(i,ii),temp_time_vector_for_condition_A2(i,ii)] = Mymin (DATA_1{i,2}(Var_A_electrodes(1,ii),  start_var_A :seg_end_var_A),sampling_rate,start_var_A);
                             [temp_vector_for_condition_B1(i,ii),temp_time_vector_for_condition_B1(i,ii)] = Mymin (DATA_1{i,3}(Var_A_electrodes(1,ii),  start_var_A :seg_end_var_A),sampling_rate,start_var_A);
                             [temp_vector_for_condition_B2(i,ii),temp_time_vector_for_condition_B2(i,ii)] = Mymin (DATA_1{i,4}(Var_A_electrodes(1,ii),  start_var_A :seg_end_var_A),sampling_rate,start_var_A);

                        end  
                        
             elseif Mean_peak == 4
                
                        for ii = 1 : length( Var_A_electrodes)

                             [temp_vector_for_condition_A1(i,ii),temp_time_vector_for_condition_A1(i,ii)] = MyMed (DATA_1{i,1}(Var_A_electrodes(1,ii),  start_var_A :seg_end_var_A),sampling_rate,start_var_A);
                             [temp_vector_for_condition_A2(i,ii),temp_time_vector_for_condition_A2(i,ii)] = MyMed (DATA_1{i,2}(Var_A_electrodes(1,ii),  start_var_A :seg_end_var_A),sampling_rate,start_var_A);
                             [temp_vector_for_condition_B1(i,ii),temp_time_vector_for_condition_B1(i,ii)] = MyMed (DATA_1{i,3}(Var_A_electrodes(1,ii),  start_var_A :seg_end_var_A),sampling_rate,start_var_A);
                             [temp_vector_for_condition_B2(i,ii),temp_time_vector_for_condition_B2(i,ii)] = MyMed (DATA_1{i,4}(Var_A_electrodes(1,ii),  start_var_A :seg_end_var_A),sampling_rate,start_var_A);

                        end
                        
            end
            
  
            
            
            
        end
        
                    % this parts avreages over all electodes
            mean_vector_for_condition_A1 = mean ( temp_vector_for_condition_A1,2);
            mean_vector_for_condition_A2 = mean (temp_vector_for_condition_A2,2);
            mean_vector_for_condition_B1 = mean ( temp_vector_for_condition_B1,2);
            mean_vector_for_condition_B2 = mean (temp_vector_for_condition_B2,2);            

            if Mean_peak > 1
                
                            mean_vector_for_time_condition_A1 = mean ( temp_time_vector_for_condition_A1,2);
                            mean_vector_for_time_condition_A2 = mean (temp_time_vector_for_condition_A2,2);
                            mean_vector_for_time_condition_B1 = mean ( temp_time_vector_for_condition_B1,2);
                            mean_vector_for_time_condition_B2 = mean (temp_time_vector_for_condition_B2,2);          
                
            end

        
        %**********************************************************
                %**********************************************************
                        %**********************************************************
                        
                     %   [time_matrix] = Regression_IAT2_peak_analysis (DATA_1,listtentwe,electrolist,main_log);
                        
                        
                                %**********************************************************
                                        %**********************************************************
        
        
        
        
    
%         out = Data_Table;
%         corrcoef(out)
        
%         dependent (1:16,1) = mean_vector_for_condition_A1; 
%         dependent (33:48,1) = mean_vector_for_condition_A2; 
%         dependent (17:32,1) = mean_vector_for_condition_B1; 
%         dependent (49:64,1) = mean_vector_for_condition_B2; 
        
        dependent (1:length(mean_vector_for_condition_A1),1) = mean_vector_for_condition_A1; 
        dependent (length(mean_vector_for_condition_A1)+1:2*length(mean_vector_for_condition_A1),1) = mean_vector_for_condition_A2; 
        dependent (2*length(mean_vector_for_condition_A1)+1:3*length(mean_vector_for_condition_A1),1) = mean_vector_for_condition_B1; 
        dependent (3*length(mean_vector_for_condition_A1)+1:4*length(mean_vector_for_condition_A1),1) = mean_vector_for_condition_B2; 
        
        [stats] = Regression_IAT2_statistics (dependent);
        
        %the data itself
        
        out(1:length(mean_vector_for_condition_A1),1) = mean_vector_for_condition_A1; 
        out(1:length(mean_vector_for_condition_A1),2) = mean_vector_for_condition_A2; 
        out(1:length(mean_vector_for_condition_A1),3) = mean_vector_for_condition_B1; 
        out(1:length(mean_vector_for_condition_A1),4) = mean_vector_for_condition_B2; 
        
            if Mean_peak > 1
                
                    dependent (1:16,1) = mean_vector_for_time_condition_A1; 
                    dependent (17:32,1) = mean_vector_for_time_condition_A2; 
                    dependent (33:48,1) = mean_vector_for_time_condition_B1; 
                    dependent (49:64,1) = mean_vector_for_time_condition_B2; 

                    [time_matrix] = Regression_IAT2_statistics (dependent);  
                    
                    
                    out(31:46,1) = mean_vector_for_time_condition_A1; 
                    out(31:46,2) = mean_vector_for_time_condition_A2; 
                    out(31:46,3) = mean_vector_for_time_condition_B1; 
                    out(31:46,4) = mean_vector_for_time_condition_B2; 
                    
            else
                
                        time_matrix = 1;
                
            end        

        answer2 = menu('Would you like to print out data graphs','yes','yes - use log','no');        
        
        
            if answer2==1
                
                answer3 = inputdlg ({'Enter Var 1 cond 1 Name OR press 0 for LOG','Enter Var 1 cond 2 Name OR press 0 for LOG','Enter Var 2 cond 1 Name OR press 0 for LOG','Enter Var 2 cond 2 Name OR press 0 for LOG'});
                
                
                
                
                        if (strcmp(answer3(1,1), '0'));
                            condition_names{1,1} = main_log{11,1};
                        else
                            condition_names{1,1} = (answer3(1,1));
                        end                 
                
                        
                        if (strcmp(answer3(2,1), '0'));
                            condition_names{2,1} = main_log{12,1};
                        else
                            condition_names{2,1} = (answer3(2,1));
                        end                          

                        
                        if (strcmp(answer3(3,1), '0'));
                            condition_names{3,1} = main_log{13,1};
                        else
                            condition_names{3,1} = (answer3(3,1));
                        end                          

                        
                        if (strcmp(answer3(4,1), '0'));
                            condition_names{4,1} = main_log{14,1};
                        else
                            condition_names{4,1} = (answer3(4,1));
                        end                          
                        
                        
                       Log{11,1} =  condition_names{1,1};
                       Log{12,1} =  condition_names{2,1};
                       Log{13,1} =  condition_names{3,1};                       
                       Log{14,1} =  condition_names{4,1}; 
                             
                       
                       
                       graphing (DATA_1,Var_A_electrodes,condition_names,Variable_1_name,start_var_A,seg_end_var_A,sampling_rate);
                  
            elseif  answer2==2   
                        
                
                        condition_names{1,1} = main_log{11,1};
                        condition_names{2,1} = main_log{12,1};
                        condition_names{3,1} = main_log{13,1};
                        condition_names{4,1} = main_log{14,1};                        
                
                       Log{11,1} =  main_log{11,1};
                       Log{12,1} =  main_log{12,1};
                       Log{13,1} =  main_log{13,1};                      
                       Log{14,1} =  main_log{14,1};

                       graphing (DATA_1,Var_A_electrodes,condition_names,Variable_1_name,start_var_A,seg_end_var_A,sampling_rate);
                
            elseif  answer2==3   
                
                       Log{11,1} =  main_log{11,1};
                       Log{12,1} =  main_log{12,1};
                       Log{13,1} =  main_log{13,1};                      
                       Log{14,1} =  main_log{14,1};
                       
                       
            end

            answer3 = menu('Would you like to print out topoplot','yes - (1-2 & 3-4)','yes - (1-3 & 2-4)','yes - (AVG(1&2) - AVG(2&4)','yes - (AVG(1&3) - AVG(2&4)', 'yes - (AVG(1&4) - AVG(2&3)', 'yes - use log','no');    
            
            if answer3 <7
                
                [topoploting] = Regression_IAT2_topoploting (DATA_1,start_var_A,seg_end_var_A, sampling_rate,Log,answer3);
                
            end
       
end



function [time_matrix] = Regression_IAT2_peak_analysis (DATA_1,listtentwe,electrolist,main_log)

        %********************************************************* 
        % this part does peak analysis
         for i = 1 : length(DATA_1)
            
            
            %this for runs on the selected electrodes and avreages the data between time points (which I use usully for emotion and words).
            for ii = 1 : length( Var_A_electrodes)
                 
                 temp_peak_data_for_condition_A1 (ii,1: (seg_end_var_A-start_var_A+1)) = DATA_1{i,1}(Var_A_electrodes(1,ii),  start_var_A :seg_end_var_A);
                 temp_peak_data_for_condition_A2 (ii,1: (seg_end_var_A-start_var_A)+1) = DATA_1{i,2}(Var_A_electrodes(1,ii),  start_var_A :seg_end_var_A);

              
            end
            
            % this parts avreages over all electodes
            mean_temp_peak_data_for_condition_A1 = mean (temp_peak_data_for_condition_A1);
            mean_temp_peak_data_for_condition_A2 = mean (temp_peak_data_for_condition_A2);
            
            % this part extract peaks, in the data cells 1 & 2 are for
            % condition A_1 and cells 3 & 4 are for conditios A_2
            [pks,locs] = findpeaks (mean_temp_peak_data_for_condition_A1);
            Data_Table_peaks {1,i,1} = pks;
            Data_Table_peaks {1,i,2} = locs;
            [pks,locs] = findpeaks (mean_temp_peak_data_for_condition_A2);
            Data_Table_peaks {1,i,3} = pks;
            Data_Table_peaks {1,i,4} = locs;
            
            [maxval,locs] = max (mean_temp_peak_data_for_condition_A1);
            Data_Table_peaks {1,i,5} = maxval;
            Data_Table_peaks {1,i,6} = locs;
            [maxval,locs] = max (mean_temp_peak_data_for_condition_A2);
            Data_Table_peaks {1,i,7} = maxval;
            Data_Table_peaks {1,i,8} = locs;

            [maxval,locs] = min (mean_temp_peak_data_for_condition_A1);
            Data_Table_peaks {1,i,9} = maxval;
            Data_Table_peaks {1,i,10} = locs;
            [maxval,locs] = min (mean_temp_peak_data_for_condition_A2);
            Data_Table_peaks {1,i,11} = maxval;
            Data_Table_peaks {1,i,12} = locs;            
            
            %This parts begins the work on variabele B
            for ii = 1 : length( Var_B_electrodes)
                
                              
                 temp_peak_data_for_condition_B1 (ii,1: (seg_end_var_B-start_var_B+1)) = DATA_1{i,3}(Var_B_electrodes(1,ii),  start_var_B :seg_end_var_B);
                 temp_peak_data_for_condition_B2 (ii,1: (seg_end_var_B-start_var_B)+1) = DATA_1{i,4}(Var_B_electrodes(1,ii),  start_var_B :seg_end_var_B);

                
            end

            mean_peak_vector_for_condition_B1 = mean (temp_peak_data_for_condition_B1);
            mean_peak_vector_for_condition_B2 = mean (temp_peak_data_for_condition_B2);
            
            [pks,locs] = findpeaks (mean_peak_vector_for_condition_B1);
            Data_Table_peaks {2,i,1} = pks;
            Data_Table_peaks {2,i,2} = locs;
            [pks,locs] = findpeaks (mean_peak_vector_for_condition_B2);
            Data_Table_peaks {2,i,3} = pks;
            Data_Table_peaks {2,i,4} = locs;

            [maxval,locs] = max (mean_peak_vector_for_condition_B1);
            Data_Table_peaks {2,i,5} = maxval;
            Data_Table_peaks {2,i,6} = locs;
            [maxval,locs] = max (mean_peak_vector_for_condition_B2);
            Data_Table_peaks {2,i,7} = maxval;
            Data_Table_peaks {2,i,8} = locs;

            [maxval,locs] = min (mean_peak_vector_for_condition_B1);
            Data_Table_peaks {2,i,9} = maxval;
            Data_Table_peaks {2,i,10} = locs;
            [maxval,locs] = min (mean_peak_vector_for_condition_B2);
            Data_Table_peaks {2,i,11} = maxval;
            Data_Table_peaks {2,i,12} = locs;              
            
            % Note that the two data matrix are not ! built in the same
            % way.

            

            
            
         end
        %***********************************************************
                %**********************************************************
                        %**********************************************************
                                %**********************************************************
                                        %**********************************************************
        time_matrix = Data_Table_peaks;

end


function [stats] = Regression_IAT2_statistics (dependent)

                   variable_A_vector (1:length(dependent)/2,1) = 1; 
                   variable_A_vector (length(dependent)/2+1:length(dependent),1) = 2; 
                    
                   variable_B_vector (1:length(dependent)/4,1) = 1; 
                   variable_B_vector (length(dependent)/2+1:length(dependent)*0.75,1) = 1; 
                   variable_B_vector (length(dependent)/4+1:length(dependent)/2,1) = 2; 
                   variable_B_vector (length(dependent)*0.75+1:length(dependent),1) = 2; 
            
%                    Subjects = [1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16];
                        for ii = 1 : 4 ; for i = 1:length(dependent)/4 ; Subjects((ii-1)*length(dependent)/4+i,1) = i;end;end
                   
                   stats = rm_anova2(dependent,Subjects,variable_A_vector,variable_B_vector,{'type','Congrouncy'});

end



function [log] = Regression_IAT2_topoploting (DATA_1,start_var_A,seg_end_var_A, sampling_rate,log,answer3)

            % load Roni's data
            load('UNIT801_avg.mat')

            % change to Uri 
            uriData=avUNIT801RelNew;

            % edit time (change to equation)
            time = -0.1:0.00785:1;
            uriData.time=time;

            % edit other parametrs
            uriData.var=uriData.var(:,1:141);
            uriData.dof=uriData.dof(:,1:141);

            
            %creating avreages

            first = DATA_1{1,1};
            second = DATA_1{1,2};
            three = DATA_1{1,3};
            four = DATA_1{1,4};

            for i = 2 : 16

                first= first+ DATA_1{i,1};
                second= second+ DATA_1{i,2};
                three= three+ DATA_1{i,3};
                four= four+ DATA_1{i,4};

            end

            first= first/16;
            second=second/16;
            three=three/16;
            four=four/16;
            
            first_minus_second = first-second;
            three_minus_four = three-four;
            first_minus_three = first-three;
            second_minus_four = second-four;
            
            Odd = ((first+second)/2)  -  ((three+four)/2);
            Even = ((first+three)/2)  -  ((second+four)/2);
            
            one_four_and_two_three =  ((first+four)/2)  -  ((three+second)/2);
            
            cfg=[];
            cfg.interactive='yes';
            cfg.layout='biosemi64.lay';
            cfg.colorbar='yes';
     
            % edit data remember to enter log
            
            if answer3 == 1
                
                    temp=first_minus_second;
                    temp=temp(3:66,:);
                    uriData.avg=temp;
                    
                    cfg.zlim=[-0.2 1.5];
                    figure;
                    title('first - second');
                    cfg.xlim=[(start_var_A/(sampling_rate/1000)-100)/1000   (seg_end_var_A/(sampling_rate/1000)-100)/1000];
                    ft_topoplotER(cfg,uriData)
                
            
                    temp= three_minus_four;
                    temp=temp(3:66,:);
                    uriData.avg=temp;
                    
                    cfg.zlim=[-0.2 1.5];
                    figure;
                    title('three - four');
                    cfg.xlim=[(start_var_A/(sampling_rate/1000)-100)/1000   (seg_end_var_A/(sampling_rate/1000)-100)/1000];
                    ft_topoplotER(cfg,uriData)            
            
            elseif answer3 == 2
                               
                    temp=first_minus_three;
                    temp=temp(3:66,:);
                    uriData.avg=temp;
                    
                    %cfg.zlim=[-0.7 0.7];
                    figure;
                    title('first - three');
                    cfg.xlim=[(start_var_A/(sampling_rate/1000)-100)/1000   (seg_end_var_A/(sampling_rate/1000)-100)/1000];
                    ft_topoplotER(cfg,uriData)
                
            
                    temp=  second_minus_four;
                    temp=temp(3:66,:);
                    uriData.avg=temp;
                    
                    %cfg.zlim=[-0.7 0.7];
                    figure;
                    title('second - four');
                    cfg.xlim=[(start_var_A/(sampling_rate/1000)-100)/1000   (seg_end_var_A/(sampling_rate/1000)-100)/1000];
                    ft_topoplotER(cfg,uriData)            

                    
                    
             elseif answer3 == 3
                               
                    temp=Odd;
                    temp=temp(3:66,:);
                    uriData.avg=temp;
                    
                    %cfg.zlim=[-0.7 0.7];
                    figure;
                    title('1&2 - 3&4');
                    cfg.xlim=[(start_var_A/(sampling_rate/1000)-100)/1000   (seg_end_var_A/(sampling_rate/1000)-100)/1000];
                    ft_topoplotER(cfg,uriData)

 
             elseif answer3 == 4
                               
                    temp=Even;
                    temp=temp(3:66,:);
                    uriData.avg=temp;
                    
                    %cfg.zlim=[-0.7 0.7];
                    figure;
                    title('1&3 - 2&4');
                    cfg.xlim=[(start_var_A/(sampling_rate/1000)-100)/1000   (seg_end_var_A/(sampling_rate/1000)-100)/1000];
                    ft_topoplotER(cfg,uriData)
                   
             elseif answer3 == 5
                               
                    temp=one_four_and_two_three;
                    temp=temp(3:66,:);
                    uriData.avg=temp;
                    
                    %cfg.zlim=[-0.7 0.7];
                    figure;
                    title('1&4 - 2&3');
                    cfg.xlim=[(start_var_A/(sampling_rate/1000)-100)/1000   (seg_end_var_A/(sampling_rate/1000)-100)/1000];
                    ft_topoplotER(cfg,uriData)          
                    
            end
            
            % plot equation for time still requiered

            
            
end


function [out1,out2] = MyMed (uri,sampling_rate,start_var_A)
%I add a 100 because the minuses in some vector drives this nuts
temp2 =0;
uri = uri +100;
    for i =1 : length (uri) 
        
            temp = uri(1,i);
            temp2 = temp2 +temp;
    
        if temp2>=sum(uri)/2  
            out1=uri(1,i) - 100;
            temp3 = i +  start_var_A;           
            %out2 = temp3/sampling_rate*1000-100;
            out2=i;
            break
        end
        
    end
        
end



function [out1,out2] = Mymax (data,sampling_rate,start_var_A)
%I add a 100 because the minuses in some vector drives this nuts

[out1,out2] = max (data);

out2 = out2 + start_var_A;
out2 = out2/sampling_rate*1000-100;
        
end


function [out1,out2] = Mymin (data,sampling_rate,start_var_A)
%I add a 100 because the minuses in some vector drives this nuts

[out1,out2] = min (data);

out2 = out2 + start_var_A;
out2 = out2/sampling_rate*1000-100;
        
end